import 'package:auto_route/auto_route.dart';
import 'package:distribution_mall_flutter/constant/cf_constant.dart';
import 'package:distribution_mall_flutter/entity/order/detail/order_detail_entity.dart';
import 'package:distribution_mall_flutter/generated/l10n.dart';
import 'package:distribution_mall_flutter/pages/pay/pay_list/pay_list_provider.dart';
import 'package:distribution_mall_flutter/provider/common/pay.dart';
import 'package:distribution_mall_flutter/provider/order/order_detail.dart';
import 'package:distribution_mall_flutter/utils/common_widget.dart';
import 'package:distribution_mall_flutter/utils/utils.dart';
import 'package:distribution_mall_flutter/widgets/modal_pay.dart';
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:slide_countdown/slide_countdown.dart';

@RoutePage()
class PayQrCodePage extends ConsumerStatefulWidget {
  const PayQrCodePage({super.key});

  @override
  createState() {
    return _PayQrCodePage();
  }
}

class _PayQrCodePage extends ConsumerState<PayQrCodePage> {
  @override
  void initState() {
    super.initState();
    ref.read(orderDetailProvider.notifier).getOrderDetail('123123').then((bol) {
      if (!bol) return;
      OrderDetailEntity? detail = ref.watch(orderDetailProvider).detal;
      if (detail == null) return;
      ref.read(payListProvider.notifier).getPayList(
          totalAmount: detail.amount?.totalAmount, isCanCod: detail.isCanCod);
    });
  }

  @override
  Widget build(BuildContext context) {
    OrderDetailEntity? detail = ref.watch(orderDetailProvider).detal;
    ref.watch(payListProvider);
    return Scaffold(
        appBar: AppBar(
          scrolledUnderElevation: 0,
          backgroundColor: Colors.white,
          title: Text(S.current.payment_method),
          centerTitle: true,
          leading: Padding(
            padding: const EdgeInsets.only(left: 16),
            child: CommonBtnWidget.arrowBack(),
          ),
        ),
        bottomNavigationBar: Container(
            width: double.infinity,
            height: 98,
            child: Column(
              children: [
                Row(
                  children: [
                    Text(
                      S.current.pay_within,
                      style: const TextStyle(
                          color: Color.fromRGBO(255, 0, 0, 1),
                          fontSize: 14,
                          letterSpacing: TextConstant.letterSpacing),
                    ),
                    SlideCountdown(
                      // duration: Duration(hours: getTimeDiffernce),
                      decoration: const BoxDecoration(),
                      style: const TextStyle(
                          color: Color.fromRGBO(255, 0, 0, 1),
                          fontSize: 14,
                          letterSpacing: TextConstant.letterSpacing),
                    )
                  ],
                ),
                CommonBtnWidget.generalBtn(() {
                  // appRouter.push(const DeleteAccountLoadingRoute());
                }, text: S.current.order_status_to_pay, fullWidthButton: true)
              ],
            )),
        body: SingleChildScrollView(
          child: Column(
            children: [
              Container(
                  child: Column(
                children: [
                  Text(S.current.pay_amount),
                  Padding(
                      padding: const EdgeInsets.only(top: 14),
                      child: Utils.currencyWidget(detail?.amount?.totalAmount,
                          commonStyle: const TextStyle(
                              fontSize: 28,
                              fontWeight: FontWeight.bold,
                              color: Color.fromRGBO(227, 50, 11, 1))))
                ],
              )),
              Container(
                margin: const EdgeInsets.only(top: EdgeConstant.edge20),
                padding:
                    const EdgeInsets.symmetric(horizontal: EdgeConstant.edge20),
                child: Column(
                  children: [PayListItem()],
                ),
              )
            ],
          ),
        ));
  }
}
